<template>
  <el-container class="main-container">
    <el-header>
      <img src="../assets/images/logo.png" alt="" />
      <!-- 头部 右侧的菜单 -->
      <el-menu mode="horizontal" background-color="#23262e" text-color="#fff" active-text-color="#409eff">
        <!-- 下面的菜单没有下拉菜单，则使用 el-menu-item 标签 -->
        <!-- <el-menu-item>处理中心</el-menu-item> -->
        <!-- 下面的菜单有下拉菜单，则使用 el-submenu 标签 -->
        <el-submenu index="1">
          <template slot="title">
            <img class="avatar" :src="user.user_pic" alt="" v-if="user.user_pic" />
            <img class="avatar" src="../assets/1.jpg" alt="" v-else />
            个人中心
          </template>
          <el-menu-item index="1-1"><i class="el-icon-edit"></i>用户资料</el-menu-item>
          <el-menu-item index="1-2"><i class="el-icon-edit"></i>重置密码</el-menu-item>
          <el-menu-item index="1-3"><i class="el-icon-edit"></i>更换头像</el-menu-item>
        </el-submenu>
        <el-menu-item index="2"><i class="el-icon-switch-button"></i>退出</el-menu-item>
      </el-menu>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <div class="user-info">
          <img class="avatar" :src="user.user_pic" alt="" v-if="user.user_pic" />
          <img class="avatar" src="../assets/1.jpg" alt="" v-else />
          <!-- 有昵称nickname，则使用昵称，没有昵称，只能使用账号username -->
          <span>欢迎你 {{ user.nickname || user.username }}</span>
        </div>
        <!-- 侧边栏的菜单 -->
        <el-menu
          background-color="#23262e"
          text-color="#fff"
          active-text-color="#409eff"
          default-active="aaa"
          unique-opened
          class="aside-menu"
        >
          <el-menu-item index="aaa"><i class="el-icon-edit"></i>首页</el-menu-item>
          <el-submenu index="abc">
            <template slot="title"><i class="el-icon-edit"></i>文章管理</template>
            <el-menu-item index="bbb"><i class="el-icon-edit"></i>文章分类</el-menu-item>
            <el-menu-item index="ccc"><i class="el-icon-edit"></i>文章列表</el-menu-item>
          </el-submenu>
          <el-submenu index="bcd">
            <template slot="title"><i class="el-icon-edit"></i>个人中心</template>
            <el-menu-item index="ddd"><i class="el-icon-edit"></i>基本资料</el-menu-item>
            <el-menu-item index="eee"><i class="el-icon-edit"></i>重置密码</el-menu-item>
            <el-menu-item index="fff"><i class="el-icon-edit"></i>更换头像</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>Main</el-main>
        <el-footer>Footer</el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>
<script>
import { mapState } from 'vuex'
export default {
  created() {
    // 调用vuex中的 actions 中的 getUser 方法
    // this.$store.dispatch('模块名/方法名')
    this.$store.dispatch('user/getUser')
  },
  computed: {
    // ...mapState('模块名', ['xxx', 'xxxx'])
    ...mapState('user', ['user'])
  }
}
</script>
<style lang="less">
.main-container {
  height: 100%;
}
.el-header,
.el-aside {
  background-color: #23262e;
}
.el-main {
  background-color: #f2f2f2;
}
.el-footer {
  background-color: #eee;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.aside-menu {
  width: 200px;
}
.avatar {
  width: 35px;
  height: 35px;
  background-color: #fff;
  border-radius: 50%;
  margin-right: 15px;
  // object-fit: cover 和 background-size基本一个意思
  // 表示让图片按照原始的比例完整的显示出来
  object-fit: cover;
}
.user-info {
  height: 70px;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
}
</style>
